import 'package:enterprise_v6_app/app/components/custom_modele/custom_search_enter.dart';
import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_title_chart_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/ext.dart';
import 'package:enterprise_v6_app/app/data/entities/double_control/promise_day_record_list_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/double_prevention_page/risk_control_page/daily_commitment/daily_commitment_controller.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';

///每日承诺
class DailyCommitmentPage extends StatelessWidget {
  DailyCommitmentPage({super.key}) {
    Get.lazyPut(DailyCommitmentController.new);
  }

  @override
  Widget build(BuildContext context) {
    final DailyCommitmentController controller = Get.find<DailyCommitmentController>();
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            key: controller.popRightScaffoldKey,
            body: Container(
              color: const Color(0xffF5F5F6),
              padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.w),
              child: Column(
                children: [
                  _getSearchConditionWidget(controller),
                  AppGaps.vGap12,
                  Expanded(
                      child: CustomEasyRefreshList<PromiseDayRecordListEntity>(
                    key: controller.globalKey,
                    dataLoad: controller.equipmentInspectionLedgerList,
                    itemBuilder: (PromiseDayRecordListEntity item, int index) {
                      return CustomTitleChartPage(
                        title: item.promiseName ?? '',
                        titleRightWidget: _getResult(item.promiseTime),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            _getTextView(title: '承诺人：', value: item.promiseUserName ?? ''),
                            AppGaps.vGap12,
                            _getTextView(title: '承诺时间：', value: item.promiseTime ?? ''),
                            AppGaps.vGap12,
                            _getTextView(title: '生成时间：', value: item.createDate ?? ''),
                          ],
                        ).clickOnce(() {
                          Get.toNamed(AppRoutes.dailyCommitmentDetailPage, arguments: item.id);
                        }),
                      );
                    },
                  ))
                ],
              ),
            ),
            // endDrawer: Container(
            //   width: AppDimens.sw - 100.w,
            //   height: AppDimens.sh,
            //   color: Colors.white,
            //   child: CustomFilterRightSheet(
            //     dataList: controller.filterList,
            //     onConfirm: controller.screenConfirm,
            //     isRadio: true,
            //     isShowTime: true,
            //   ),
            // ),
          );
        });
  }

  ///获取条件搜索项
  Widget _getSearchConditionWidget(DailyCommitmentController controller) {
    return Row(
      children: [
        Expanded(
            child: CustomSearchEnter(
          height: 32.w,
          hintText: '请输入承诺名称',
          text: controller.searchX,
          onCallBack: (value) {
            controller.searchX = value;
            controller.refreshPage();
          },
        )),
        AppGaps.hGap8,
        _screen(controller),
      ],
    );
  }

  ///筛选
  Widget _screen(DailyCommitmentController controller) {
    return Container(
      width: 36.w,
      height: 32.w,
      alignment: Alignment.center,
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
      child: SvgPicture.asset(
        AppImages.icon_search_screen,
        width: 18.w,
        height: 16.w,
      ),
    ).clickOnce(controller.screen);
  }

  /// 获取字段显示
  Widget _getTextView({required String title, required String value, Color? valueColor}) {
    return Row(
      children: [
        Text(
          title,
          style: TextStyle(
            fontSize: 13.sp,
            height: 1.2,
            fontWeight: FontWeight.w400,
            color: const Color(0xffA5A6B5),
          ),
        ),
        Expanded(
            child: Container(
          alignment: Alignment.centerRight,
          child: Text(
            value,
            style: TextStyle(
              fontSize: 12.sp,
              height: 1.2,
              fontWeight: FontWeight.w400,
              color: valueColor ?? const Color(0xff495061),
            ),
          ),
        ))
      ],
    );
  }

  /// 状态根据承诺时间判断不为空就是已承诺 为空就是未承诺
  Widget _getResult(String? i) {
    switch (i) {
      case null:
        return _title('未承诺', const Color(0xFFFD6B6B));
      case '':
        return _title('未承诺', const Color(0xFFFD6B6B));
      default:
        return _title('已承诺', const Color(0xFF5C6DFF));
    }
  }

  Widget _title(String title, Color color) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 2.w, horizontal: 11.w),
      decoration: BoxDecoration(
          color: color,
          borderRadius: const BorderRadius.only(
            topLeft: Radius.circular(10),
            topRight: Radius.circular(10),
            bottomRight: Radius.circular(10),
          )),
      child: Text(
        title,
        style: TextStyle(
          color: Colors.white,
          fontSize: 10.sp,
          fontWeight: FontWeight.w400,
        ),
      ),
    );
  }
}
